import {
	ref
} from 'vue'
import {
	hint,
	port
} from './port.js'


export const captchaText = ref('获取验证码')
let countDown = 59
let timer = null

export async function sendCode(params) {
	if (timer) return

	if (!params.mobile || !params.mobile.trim()) {
		hint('手机号为空')
		return
	}

	const res = await port('captchaSend', params)
	console.log(res);
	hint(res.msg)

	captchaText.value = `${countDown}s`
	timer = setInterval(() => {
		countDown--
		captchaText.value = `${countDown}s`
		if (countDown < 1) {
			clearInterval(timer)
			timer = null
			countDown = 59
			captchaText.value = '获取验证码'
		}
	}, 1000)
}